package com.testDemo.hutool;

import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.date.TemporalUtil;
import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

/**
 * @author: zour
 * @date: 2024/6/15
 * @description:
 */
public class LocalDateTimeUtilTest {

    @Test
    public void between(){
//        LocalDateTime expire_in = TemporalUtil.offset(LocalDateTime.now(), 7200, ChronoUnit.SECONDS);
//        System.out.println(  LocalDateTimeUtil.between(LocalDateTime.now(), expire_in, ChronoUnit.MINUTES) );
//        System.out.println(  LocalDateTimeUtil.between(LocalDateTime.now(), expire_in, ChronoUnit.MINUTES) < 10);
        LocalDateTime localDateTime = LocalDateTime.of(2023, 1, 18, 0, 0, 0);
        localDateTime = LocalDateTime.of(2023, 1, 19, 0, 0, 0);
        long between = LocalDateTimeUtil.between(localDateTime,LocalDateTime.now(), ChronoUnit.MONTHS);
        System.out.println(between);//20
        localDateTime = LocalDateTime.of(2023, 1, 20, 0, 0, 0);

        between = LocalDateTimeUtil.between(localDateTime,LocalDateTime.now(), ChronoUnit.MONTHS);
        System.out.println(between);//19
        between = LocalDateTimeUtil.between(localDateTime,LocalDateTime.now(), ChronoUnit.MONTHS);
        System.out.println(between);//19

        localDateTime = LocalDateTime.of(2023, 1, 30, 0, 0, 0);
        between = LocalDateTimeUtil.between(localDateTime, LocalDateTime.of(2024, 2, 29, 0, 0, 0), ChronoUnit.MONTHS);
        System.out.println(between);//12
        between = LocalDateTimeUtil.between(localDateTime, LocalDateTime.of(2024, 3, 1, 0, 0, 0), ChronoUnit.MONTHS);
        System.out.println(between);//13
    }
}
